<?php session_start();?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta http-equiv="Content-Language" content="es">
        <meta name="Robots" content="all">
        <meta name="Distribution" content="global">
        <meta name="description" content="iRestauranting monitoriza las principales páginas sobre restauración, valoramos tu presencia en Internet, las opiniones de tus clientes y la actividad sobre tu restaurante">
        <link rel="icon" href="img/favicon.ico" type="image/x-icon" >
        <title>iRestauranting - Registro en iRestauranting</title>
        <link rel="stylesheet" media="all" href="../css/irestauranting.css" >
    	<link rel="stylesheet" media="screen and (max-width: 1023px)" href="../css/irestauranting_tablet.css" >
        <link rel="stylesheet" href="../css/magnific-popup.css" >	
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" >
    	<link href='http://fonts.googleapis.com/css?family=PT+Sans' rel='stylesheet' type='text/css'>
		<link rel="stylesheet" type="text/css" href="../css/token-input-facebook.css" />
</head>

<body>
	<div>
        <div id="resto_header">
        	<div id="header-center">
                <div style="float:left">
                	<a href="../index.html"><img src="../img/LogoHome.png" /></a>
                </div>
                <div style="margin-left:30px;float:left">
                 	<img src="../img/barra_header.png" />
                 </div>
                 <div style="margin-top:20px;margin-left:30px;float:left;">
                 	<a style="text-decoration: none;"  href="../como_funciona.html"><span style="color:#FFF" class="texto_span_16_bold">Cómo funciona</span></a>
                 </div>
                 <div style="margin-left:30px;float:left">
                 	<img src="../img/barra_header.png" />
                 </div>
                 <div  style="margin-top:20px;margin-left:30px;float:left">
                 	<a style="text-decoration: none;" href="../que_te_ofrecemos.html"><span style="color:#FFF" class="texto_span_16_bold">Qué te ofrecemos</span></a>
                 </div>
                 <div style="margin-left:30px;float:left">
                 	<img src="../img/barra_header.png" />
                 </div>
                 <div  style="margin-top:20px;margin-left:30px;float:left">
                 	<a id="contact_form_link" style="text-decoration: none;" href="#contact-popup"><span style="color:#FFF" class="texto_span_16_bold">Contacto</span></a>
                 </div>
             </div>
         </div>
         <div id="separador_header">
         </div>	
         <div style="clear:both" />
         <div id="container_login">
         	<div class="texto_30">Registro en iRestauranting</div>
         	<div id="login" style="border-radius:10px;display:block;width:520px;padding:30px 0 30px;margin:auto">
            	
                	<p>
                    ¡Se ha actualizado correctamente el perfil de tu usuario en iRestauranting!<br/>
                    </p>
                    
                    <br/><br/>
                    <a href="../login/login.html"><img src="../img/BotonEntrar.png"  /></a>
                </form>
            </div>
        </div>
        
     </div>
	<div style="clear:both" ></div>
	<div id="separador_footer" style="position:absolute;bottom:60px;">
	</div>
	<div id="resto_footer" style="position:absolute;bottom:0px;">
    
	</div>
    
   
</body>
</html>
<?php

	define("MAX_LENGTH", 6);

	$name = $_POST['name'];
	$name_complete = $_POST['name_complete'];
	$email = $_POST['email'];
	$ids_restos = $_POST['resto_search'];
	
	$restos = split(",",$ids_restos);
		
	if (!$name) return;
	
	set_include_path('../140dev/db');
	
	require_once('140dev_config.php');	  
	require_once('db_lib.php');
	
	$oDB = new db;
    
 	if(!$oDB)
  	{
  		die('Could not connect: ' . mysql_error());
  	}
	
	try{
		$oDB->update('MAST_USERS', "DS_USER_ID=TRIM(LOWER('".  $name . "')), DS_USER_NAME='".  $name_complete . "', DS_USER_EMAIL='".  $email . "'","ID_USER = " . $_SESSION['id_user']);
	
		
		// get user id
		$result = $oDB->select("SELECT ID_USER FROM MAST_USERS WHERE LOWER(DS_USER_ID) = TRIM(LOWER('" . $name . "'));");
		if($row = mysqli_fetch_row($result)){
			$id_user = $row[0];
		}
		
		// delete restaurants
		$oDB->delete('MAST_USERS_RESTAURANTS',"ID_USER='" . $id_user . "'");
		// insert restaurants
		foreach($restos as $resto){
			$oDB->insert('MAST_USERS_RESTAURANTS',"ID_USER='".  $id_user . "', ID_RESTAURANT='".  $resto . "'");
		}
	}
	catch(Exception $e){
		print $e;
	}	

?>